// TOWN SCRIPT
//    Town 1: Dargoth

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
// 1, 0 = Intro dialog
// 1, 1 = Museum message
// 1, 2 = Storeroom message
// 1, 3 = Pool sign
// 1, 4 = Narn God message
// 1, 5 = Conversation flag
// 1, 6 = inn flag

begintownscript;

variables;

short choice, x, ds;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(5);

	set_name(6, "The Bishop");
	set_char_dialogue_pic(6, 1955, 0);
	set_name(14, "James");
	set_char_dialogue_pic(14, 1945, 0);
	set_name(21, "James");
	set_char_dialogue_pic(21, 1958, 0);
	set_name(22, "Jamie");
	set_char_dialogue_pic(22, 1947, 0);
	set_name(23, "James");
	set_char_dialogue_pic(23, 1961, 0);
	set_name(24, "Jamie");
	set_char_dialogue_pic(24, 1950, 0);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
	if (get_flag(1, 0) == FALSE) {
		set_flag(1, 0, TRUE);
		reset_dialog();
		add_dialog_str(0, "You've entered the legendary city of Dargoth, home of the Temple of Narn.", 0);
		add_dialog_str(1, "The temple being the place where Turin created the Staff many centuries ago.", 0);
		add_dialog_str(2, "Dargoth is also where the staff was kept until stolen.", 0);
		add_dialog_str(3, "A museum is currently in the house where the staff used to be kept, an ode to days of old.", 0);
		add_dialog_str(4, "The monks and priests of the temple along with the temple guards keep Dargoth relatively safe.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(TRUE);
	}
break;

beginstate 10;
	reset_dialog();
	add_dialog_str(0, "A small brass plaque attached to the stand says:", 0);
	add_dialog_str(1, "Stand that the Staff of Turin used to be kept on.", 10);
	add_dialog_str(2, "A small layer of dust currently covers the stand.", 0);
	add_dialog_choice(0, "Ok");
	choice = run_dialog(TRUE);
break;

beginstate 11;
	reset_dialog();
	add_dialog_str(0, "The shelves are full of dusty books covering all aspects of the Staff of Turin.", 0);
	add_dialog_str(1, "None of them seem like they will help in your quest.", 0);
	add_dialog_str(2, "There sure are a lot of them though.", 0);
	add_dialog_choice(0, "Ok");
	choice = run_dialog(TRUE);
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0, "The shelves in the room seem to cover important people in The Wilderness.", 0);
	add_dialog_str(1, "You see a whole shelf dedicated to Turin.", 0);
	add_dialog_str(2, "A book on the bottom shelf seems to be about a boy named James.", 0);
	add_dialog_str(3, "Leafing through a few of them does not provide any answers to your quest.", 0);
	add_dialog_choice(0, "Ok");
	choice = run_dialog(TRUE);
break;

beginstate 13;
	if (get_flag(1, 1) == FALSE) {
		set_flag(1, 1, TRUE);
		reset_dialog();
		add_dialog_str(0, "As you eyes adjust to the dim interior, you see a caretaker looking at a book.", 0);
		add_dialog_str(1, "The rest of the place looks a little run-down.", 0);
		add_dialog_str(2, "It doesn't look like many visit the place anymore.", 0);
		add_dialog_str(3, "A stand of some sort dominates the middle of the room.", 0);
		add_dialog_choice(0, "Ok");
		choice = run_dialog(TRUE);
	}
break;

beginstate 14;
	if (get_flag(1, 2) == FALSE) {
		set_flag(1, 2, TRUE);
		message_dialog("The storeroom is full of implements and tools used by the monks to tend the fields in and around Dargoth.",
				"It doesn't look like there is much that will aid you in here.");
	}
break;

beginstate 15;
	if (get_flag(1, 3) == FALSE) {
		set_flag(1, 3, TRUE);
		message_dialog("A small sign at the head of the pool says 'Meditation Pool'.", "Please be quiet.");
	}
break;

beginstate 16;
	if (get_flag(1, 4) == FALSE) {
		set_flag(1, 4, TRUE);
		message_dialog("There is a statue of the Narn God here.  The detail is exquisite.",
				"A small rug lays in front of the statue, possibly to pray or chant on.");
	}
	else {
		print_str_color("You are by the statue of the Narn God.", 2);
	}
	if ((get_flag(50, 2) > 0) && ((has_special_item(1) > 0) ||
		(has_special_item(2) > 0) || (has_special_item(3) > 0) ||
		(has_special_item(4) > 0) || (has_special_item(5) > 0) ||
		(has_special_item(6) > 0) || (has_special_item(7) > 0))) {
		set_state_continue(100);
	}
break;

beginstate 17;
	if (get_flag(1, 6) > 0) {
		x = 36;
		ds = 3;
		set_state_continue(19);
	}
break;

beginstate 18;
	if (get_flag(1, 6) > 0) {
		x = 40;
		ds = 4;
		set_state_continue(19);
	}
break;

beginstate 19;
	set_flag(1, 6, FALSE);
	teleport_party(x, 41, 1);
	give_ter_script_message(ds, 1);
	revive_party();
	set_ticks_forward(1500);
	force_instant_terrain_redraw();
	message_dialog("The room was comfortable and relaxing.", "You awake feeling refreshed and ready for more.");
break;

beginstate 20;
	run_scenario_script(14);
break;

beginstate 21;
	run_scenario_script(15);
break;

beginstate 100;
	// put staff together again?
	reset_dialog();
	add_dialog_str(0, "You have all of the pieces of the Staff with you.", 0);
	add_dialog_str(1, "You can attempt the process to restore the staff using the chant the Sage taught you.", 0);
	add_dialog_str(2, "Do you do it?", 0);
	add_dialog_choice(0, "Restore Staff");
	add_dialog_choice(1, "Do Not Restore Staff Yet");
	choice = run_dialog(FALSE);
	if (choice == 1) {
		set_flag(50, 3, TRUE);
		message_dialog("You slowly intone the chant the Sage taught you - 'Hooey Gooey Gluey'.",
				"With the last syllable, the pieces glow, then snap together forming a staff.");
		take_special_item(1);
		take_special_item(2);
		take_special_item(3);
		take_special_item(4);
		take_special_item(5);
		take_special_item(6);
		take_special_item(7);
		reward_give(450);
		award_party_xp(500, 50);
		set_state_continue(101);
	}
break;

beginstate 101;
	// put staff back together, now show Sage beckoning party back to the hut...
	set_flag(100, 0, 2);
	message_dialog("The Sage suddenly appears in the temple.", "");
	place_monster(30, 32, 234, FALSE); // sage
	set_character_facing(86, 2);       // face him west
	force_view_center(30, 32);
	force_instant_terrain_redraw();
	put_sparkles_on_space(30, 32, 8, 12);
	run_animation_sound(10);
	pause(10);
	message_dialog("He speaks 'Return to my hut so I can finish restoring the staff.'",
			"The Sage then disappears as rapidly as he came.");
	put_sparkles_on_space(30, 32, 8, 12);
	run_animation_sound(10);
	erase_char(86); // just placed monster starts at 86
	pause(5);
break;
